while 1:
try:
n,m=map(int,input().split())
if n==m==0:
print(0,0)
break
a=[]
odd=[]
even=[]
ans=[]
for i in range(n):
a.append(int(input()))
for i in a:
if abs(i)%2==0:
even.append(i)
else:
odd.append(i)
a=sorted(odd,reverse=1)+sorted(even)
for i in range(m-1,0,-1):
for j in a:
if abs(j)%m==i and j<0:
ans.append(j)
for i in a:
if i%m==0:
ans.append(i)
for i in range(1,m):
for j in a:
if abs(j)%m==i and j>0:
ans.append(j)
print(n,m)
for i in ans:
print(i)
except:
break